var prefix = jsctx + "/rechargeOrder";

var rechargeOrder = (function () {
    function init() {
        setTimeout(function () {//防止先于-读取缓存执行
            load();
        }, 10)
    };

    function init1() {
        setTimeout(function () {//防止先于-读取缓存执行
            load1();
        }, 10)
    };

    $('#exampleTable').on('load-success.bs.table', function (e, data) {
        if (data.total && !data.rows.length) {
            $('#exampleTable').bootstrapTable('selectPage').bootstrapTable('refresh');
        }
    });

    $('#exampleTable1').on('load-success.bs.table', function (e, data) {
        if (data.total && !data.rows.length) {
            $('#exampleTable1').bootstrapTable('selectPage').bootstrapTable('refresh');
        }
    });
    var h = $(window).height() - 120;

    function load() {
        $('#exampleTable')
            .bootstrapTable(
                {
                    method: 'get',
                    url: prefix + "/listRechargeOrder",
                    iconSize: 'outline',
                    toolbar: '#exampleToolbar',
                    striped: false,
                    dataType: "json",
                    pagination: true,
                    singleSelect: false,
                    pageSize: 20,
                    pageList: [10, 20, 30],
                    // pageList: [10],
                    pageNumber: 1,
                    sidePagination: "server",
                    paginationShowPageGo: true,
                    height: h,
                    queryParams: function (params) {
                        return {
                            limit: params.limit,
                            offset: (params.offset / params.limit) + 1,
                            nickname: $("#nickname").val().trim(),
                            outTradeNo: $("#outTradeNo").val().trim(),
                            rechargeType: $("#rechargeType").val().trim(),
                            paymentType: $("#paymentType").val().trim(),
                            mobile: $("#mobile").val().trim(),
                            startTime: $("#startTime").val().trim(),
                            endTime: $("#endTime").val().trim()
                        };
                    },
                    columns: [
                        {
                            title: '#', field: '', width: '50', align: 'left',
                            formatter: function (value, row, index) {
                                return index + 1;
                            }
                        },
                        {field: 'nickname', title: '会员名', width: '100', align: 'left'},
                        {field: 'mobile', title: '会员手机号', width: '100', align: 'left'},
                        {field: 'outTradeNo', title: '商户订单号', width: '100', align: 'left'},
                        {field: 'transactionId', title: '支付订单号', width: '100', align: 'left'},
                        {field: 'amount', title: '充值金额（元）', width: '100', align: 'right'},
                        {field: 'discountAmount', title: '优惠金额（元）', width: '100', align: 'right'},
                        {field: 'factAmount', title: '实扣金额（元）', width: '100', align: 'right'},
                        {
                            field: 'rechargeType', title: '充值方式', width: '100', align: 'center',
                            formatter: function (value, row, index) {
                                if (value == '0') {
                                    return '<span class="label label-success">公众号</span>'
                                } else if (value == '1') {
                                    return '<span class="label label-info">APP</span>'
                                } else if (value == '2') {
                                    return '<span class="label label-warning">小程序</span>'
                                } else if (value == '3') {
                                    return '<span class="label label-warning">平台充值</span>'
                                }
                            }
                        },
                        //支付方式  0 微信支付  1支付宝 Z0中行微信 Z1中行支付宝 U银联支付
                        {
                            field: 'paymentType',
                            title: '支付方式',
                            width: '100', align: 'center',
                            formatter: function (value, row, index) {
                                if (value == '0') {
                                    return '<span class="label label-success">微信支付</span>'
                                } else if (value == '1') {
                                    return '<span class="label label-info">支付宝</span>'
                                } else if (value == 'Z0') {
                                    return '<span class="label label-info">中行微信</span>'
                                } else if (value == 'Z1') {
                                    return '<span class="label label-info">中行支付宝</span>'
                                } else if (value == 'U') {
                                    return '<span class="label label-info">银联支付</span>'
                                } else if (value=='C') {
                                    return '<span class="label label-info">农行支付</span>'
                                } else if (value=='ZX') {
                                    return '<span class="label label-info">中行微信支付</span>'
                                } else if (value=='3') {
                                    return '<span class="label label-info">平台充值</span>'
                                }
                            }
                        },
                        {field: 'finishTime', title: '到帐时间', width: '100', align: 'left'},
                        {
                            field: 'status', title: '到帐状态', width: '100', align: 'center',
                            formatter: function (value, row, index) {
                                if (value == '0') {
                                    return '<span class="label label-warning">未到账</span>'
                                } else if (value == '1') {
                                    return '<span class="label label-info">已到账</span>'
                                }
                            }
                        },
                        {field: 'createdTime', title: '创建时间', width: '100', align: 'left'},
                    ]
                });
    }

    function load1() {
        $('#exampleTable1')
            .bootstrapTable(
                {
                    method: 'get',
                    url: prefix + "/listRechargeOrderDetail",
                    iconSize: 'outline',
                    toolbar: '#exampleToolbar',
                    striped: false,
                    dataType: "json",
                    pagination: true,
                    singleSelect: false,
                    pageSize: 10,
                    pageList: [10, 20, 30],
                    // pageList: [10],
                    pageNumber: 1,
                    sidePagination: "server",
                    paginationShowPageGo: true,
                    height: h,
                    queryParams: function (params) {
                        return {
                            limit: params.limit,
                            offset: (params.offset / params.limit) + 1,
                            outTradeNo: $("#outTradeNo").val().trim(),
                            startTime: $("#startTime").val().trim(),
                            endTime: $("#endTime").val().trim()
                        };
                    },
                    columns: [
                        {
                            title: '#', field: '', width: '50', align: 'left',
                            formatter: function (value, row, index) {
                                return index + 1;
                            }
                        },

                        {field: 'nickname', title: '用户名', width: '100', align: 'left'},
                        {field: 'transactionId', title: '银行交易单号', width: '100', align: 'left'},
                        {field: 'outTradeNo', title: '内部交易单号', width: '100', align: 'left'},
                        {field: 'amount', title: '充值金额（元）', width: '100', align: 'right'},
                        {field: 'discountAmount', title: '减免金额（元）', width: '100', align: 'right'},
                        {field: 'factAmount', title: '实扣金额（元）', width: '100', align: 'right'},
                        {field: 'createdTime', title: '付款时间', width: '100', align: 'left'},
                        {
                            field: 'rechargeType', title: '充值方式', width: '100', align: 'center',
                            formatter: function (value, row, index) {
                                if (value == '0') {
                                    return '<span class="label label-success">公众号</span>'
                                } else if (value == '1') {
                                    return '<span class="label label-info">APP</span>'
                                } else if (value == '2') {
                                    return '<span class="label label-warning">小程序</span>'
                                }
                            }
                        },
                        //支付方式  0 微信支付  1支付宝 Z0中行微信 Z1中行支付宝 U银联支付
                        {
                            field: 'paymentType',
                            title: '支付方式',
                            width: '100', align: 'center',
                            formatter: function (value, row, index) {
                                if (value == '0') {
                                    return '<span class="label label-success">微信支付</span>'
                                } else if (value == '1') {
                                    return '<span class="label label-info">支付宝</span>'
                                } else if (value == 'Z0') {
                                    return '<span class="label label-info">中行微信</span>'
                                } else if (value == 'Z1') {
                                    return '<span class="label label-info">中行支付宝</span>'
                                } else if (value == 'U') {
                                    return '<span class="label label-info">银联支付</span>'
                                } else if (value=='C') {
                                    return '<span class="label label-info">农行支付</span>'
                                }
                            }
                        },
                    ]
                });
    }

    function reLoad() {
        $('#exampleTable').bootstrapTable('refresh');
    }

    function reLoad1() {
        $('#exampleTable1').bootstrapTable('refresh');
        selectRechargeOrderStatistics();
    }

    function goBack() {
        location.href = prefix + "/index";
    }

    function exportRechargeOrder() {

        $.fileDownload(prefix + "/exportRechargeOrder", { // 后台请求链接
            httpMethod: "get",　　　　　　　　// 请求方式
            contentType: 'application/json',　 // 请求头
            data: {　　　　　　　　　　　　　　　// 参数，左边为后台接收的参数名，右边为前端获取的值，
                nickname: $("#nickname").val().trim(),
                outTradeNo: $("#outTradeNo").val().trim(),
                rechargeType: $("#rechargeType").val().trim(),
                paymentType: $("#paymentType").val().trim(),
                mobile: $("#mobile").val().trim(),
                startTime: $("#startTime").val().trim(),
                endTime: $("#endTime").val().trim(),
                count: $("#count").val().trim() == '' ? 0 : $("#count").val().trim(),
                offset: $('.active .page-link').text(),
                limit: $(".page-size").text()
            },
            prepareCallback: function (url) {
                layer.msg("文件下载中...", {time: -1})
            },
            abortCallback: function (url) {
                // 异常终止
                layer.msg("文件下载异常！！");
            },
            successCallback: function (url) {
                layer.msg("文件下载成功！！", {time: 1500});
            },
            failCallback: function (data) {
                var str = "{" + data.substring(data.indexOf("{") + 1, data.indexOf("}")) + "}";
                layer.msg(JSON.parse(str).message);
            }
        })

    }

    function detailRechargeOrder() {
        location.href = prefix + "/detailRechargeOrderIndex";
    }

    function exportRechargeOrder1() {
        $.fileDownload(prefix + "/exportRechargeOrderDetail", { // 后台请求链接
            httpMethod: "get",　　　　　　　　// 请求方式
            contentType: 'application/json',　 // 请求头
            data: {　　　　　　　　　　　　　　　// 参数，左边为后台接收的参数名，右边为前端获取的值，
                outTradeNo: $("#outTradeNo").val().trim(),
                startTime: $("#startTime").val().trim(),
                count: $("#count").val().trim() == '' ? 0 : $("#count").val().trim(),
                endTime: $("#endTime").val().trim(),
                offset: $('.active .page-link').text(),
                limit: $(".page-size").text()
            },
            prepareCallback: function (url) {
                layer.msg("文件下载中...", {time: -1})
            },
            abortCallback: function (url) {
                // 异常终止
                layer.msg("文件下载异常！！");
            },
            successCallback: function (url) {
                layer.msg("文件下载成功！！", {time: 1500});
            },
            failCallback: function (data) {
                var str = "{" + data.substring(data.indexOf("{") + 1, data.indexOf("}")) + "}";
                layer.msg(JSON.parse(str).message);
            }
        })
    }

    return {
        init: init,
        init1: init1,
        goBack: goBack,
        reLoad: reLoad,
        reLoad1: reLoad1,
        exportRechargeOrder: exportRechargeOrder,
        detailRechargeOrder: detailRechargeOrder,
        exportRechargeOrder1: exportRechargeOrder1
    };
})();
